package cn.zirao

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import cn.zirao.R

import kotlinx.android.synthetic.main.activity_base_test.*
import zirao.base.activity.BaseActivity

class BaseTestActivity : BaseActivity(R.layout.activity_base_test, 0) {

    override fun initView() {
    }

    override fun initListener() {
        intent_no_extra!!.setOnClickListener(this)
        intent_with_extra!!.setOnClickListener(this)
        intent_with_extra_and_result!!.setOnClickListener(this)

        show_input_method!!.setOnClickListener(this)
        hide_input_method!!.setOnClickListener(this)
        font_manager!!.setOnClickListener(this)
        preference_manager!!.setOnClickListener(this)
    }

    override fun initData() {

    }

    override fun widgetClick(v: View) {
        when (v.id) {
            R.id.intent_no_extra -> openActivity(BaseIntentActivity::class.java)
            R.id.intent_with_extra -> {
                val bundle = Bundle()
                bundle.putString("HELLO", "Hello test")
                openActivity(BaseIntentActivity::class.java, bundle)
            }
            R.id.intent_with_extra_and_result -> {
                openActivity(BaseIntentActivity::class.java, null, 1000)
                showInputMethod()
            }
            R.id.show_input_method -> showInputMethod()
            R.id.hide_input_method -> hideSoftInput()
            R.id.font_manager -> openActivity(FontActivity::class.java)
            R.id.preference_manager -> openActivity(PreferencesActivity::class.java)
        }
    }

    override fun onBackPressed() {
        closeActivity(this)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 1000 && resultCode == Activity.RESULT_OK && data != null) {
            val result = data.getStringExtra("RESULT")
            showToast(result)
            outLog("BaseIntentActivity", result)
        }
    }
}
